<meta title="淘宝物料分类管理"/>
<div class="p">
    <div class="m-b-xs">
        <div class="btn-group">
            <a href="javascript:;" class="btn btn-default btn-xs"
               s-click="add()">
                <i class="fa fa-plus"></i> 新增
            </a>
        </div>
        <a href="javascript:;" class="btn btn-default btn-xs s-loading-icon "
           s-click="return $taobaoMaterialCatsGrid.refresh()">
            <i class="fa fa-refresh s-loading-spinner"></i>
        </a>
    </div>
    <div id="taobaoMaterialCatsGrid"
         s='datac,nda'
         s-data="S.get('/api/taobao-material-cat/list')">
        <table class="table table-striped table-bordered table-middle">
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>状态</th>
                <th class="text-right">操作</th>
            </tr>
            <tbody s="loop">
            <tr s-loop-role="empty">
                <td colspan="4">暂无数据</td>
            </tr>
            <tr s-loop-role="row" s="datac" class="taobaoMaterialCat">
                <td name="id"></td>
                <td name="name"></td>
                <td name="statusTitle"></td>
                <td class="text-right">
                    <input autocomplete="off" type="button" class="btn btn-xs btn-info" value="物料管理" s-click="materialList(this)"/>
                    <input autocomplete="off" type="button" class="btn btn-xs btn-danger" value="删除" s-click="del(this)"/>
                    <input autocomplete="off" type="button" class="btn btn-xs btn-info" value="编辑" s-click="edit(this)"/>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
<script type="text/javascript">
    function edit($this) {
        var data = $this.parent().data();
        S.popupOpen("/taobaoMaterialCat/taobaoMaterialCatAdd.html", {taobaoMaterialCat: data}).done(function(rs) {
           rs && $taobaoMaterialCatsGrid.refresh();
        })
    }

    function add() {
        S.popupOpen("/taobaoMaterialCat/taobaoMaterialCatAdd.html").done(function(rs) {
            rs && $taobaoMaterialCatsGrid.refresh();
        })
    }

    function del($this) {
        var data = $this.parent().data();
        S.confirm("确定删除吗").done(function() {
            S.remove("/api/taobao-material-cat/" + data.id).done(function() {
                $taobaoMaterialCatsGrid.refresh();
            })
        })
    }

    function materialList($this) {
      var data = $this.parent().data();
      S.popupOpen("/taobaoMaterialCat/taobaoMaterialList.html", {taobaoMaterialCat: data}).done(function(rs) {
        rs && $taobaoMaterialCatsGrid.refresh();
      })
    }
</script>